//
//  YJDetailTableViewCell.m
//  练习04
//
//  Created by hcios on 2017/7/6.
//  Copyright © 2017年 hcios. All rights reserved.
//

#import "YJResultTableViewCell.h"
#import "UIImageView+WebCache.h"

#define FONT_NAME_LTH                   @"FZLanTingHeiS-R-GB"

@implementation YJResultTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
}


+(instancetype)cellWithTableView:(UITableView *)tableView{
    //cell复用，唯一标识
    static NSString *identifier = @"CellID";
    //先在缓存池中取
    YJResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    //缓存池中没有再创建，并添加标识， cell移出屏幕时放入缓存池以复用
    if (cell == nil) {
        cell = [[YJResultTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);
    cell.layoutMargins = UIEdgeInsetsMake(0, 10, 0, 10);
    
    return cell;
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //取消点击高亮状态
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupSubViews];
        UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ges:)];
        self.cImageView.userInteractionEnabled = YES;
        [self.cImageView addGestureRecognizer:ges];
    }
    return self;
}


-(void)ges:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(click:)]) {
        [self.delegate click:tap];
    }
}

-(void)setupSubViews{
    //cImageView
    self.cImageView = [[UIImageView alloc] init];
    self.cImageView.layer.cornerRadius = 4;
    self.cImageView.layer.masksToBounds = YES;
    [self addSubview:self.cImageView];
    
    //topLab
    self.topLab = [[UILabel alloc] init];
    [self.topLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    [self.topLab setTextColor:[UIColor blackColor]];
    [self addSubview:self.topLab];
    
    //contextLab
    self.contextLab = [[UILabel alloc] init];
    [self.contextLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    [self.contextLab setTextColor:[UIColor blackColor]];
    [self addSubview:self.contextLab];
    
    //titleLab
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.numberOfLines = 0;
    [self.titleLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:15]];
    [self.titleLab setTextColor:[UIColor blueColor]];
    [self addSubview:self.titleLab];
}

//重写set方法
-(void)setFrameModel:(YJResultFrameModel *)frameModel{
    _frameModel = frameModel;
    YJResultModel *model = frameModel.model;
    
    [self.cImageView sd_setImageWithURL:[NSURL URLWithString:model.photo_url] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    self.cImageView.frame = frameModel.imageFrame;
    
    self.topLab.text = model.nodes_comment;
    self.topLab.numberOfLines = 0;
    self.topLab.frame = frameModel.topLabFrame;
    
    self.titleLab.text = model.nodes_entry_name;
    self.titleLab.frame = frameModel.titleFrame;
    
    self.contextLab.text = model.notes_description;
    self.contextLab.numberOfLines = 0;
    self.contextLab.frame = frameModel.contextFrame;
    
}
@end
